package com.mine.common.core.listener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * 武器装备鼠标点击监听
 * @author WangYX
 * @date 2023/11/29 16:42
 * @version 1.0.0
 */
public class EquipmentMouserListener implements MouseListener {

    private final JLayeredPane contentArea;

    private final JPanel panel;

    public EquipmentMouserListener(JLayeredPane contentArea,JPanel panel){
        this.contentArea = contentArea;
        this.panel = panel;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        remove();
        repaint();
        data();
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        Color color = new Color(236, 239, 255);
        panel.setBackground(color);
    }

    @Override
    public void mouseExited(MouseEvent e) {
        Color color = new Color(251, 248, 255);
        panel.setBackground(color);
    }

    /**
     * 移除所有组件
     */
    private void remove(){
        contentArea.removeAll();

    }

    /**
     * 重新绘制
     */
    private void repaint(){
        contentArea.repaint();
    }

    /**
     * 添加数据
     */
    private void data(){
        JPanel panel = new JPanel();
        panel.setBounds(100,0,100,100);
        JLabel label = new JLabel("2");
        panel.add(label);
        contentArea.add(panel,JLayeredPane.MODAL_LAYER);
    }




}
